{include mobile_template('header')}
<link rel="stylesheet" href="{URLROOT}/{$_G[tplurl_mobile]}/css/party.css" />
<div class="panel-comm panel-default panel-fullsize">
	<div class="panel-heading">
		<h1>$detail[subject]</h1>
		<p class="txt-small">
			<span>发起人：$detail[username]</span>
			<span class="split"></span>
			<span>发起时间：{date $detail[dateline],'w2style'}</span>
		</p>
	</div>
	<div class="panel-body">

		<div class="atab-box">
			<div class="atab-box-nav">
				<a class="atab-box-nav-link atab-box-nav-current" href="#" data-id="item_info"><span>活动信息</span></a>
				<a class="atab-box-nav-link" href="#" data-id="item_creator"><span>活动组织者</span></a>
				<a class="atab-box-nav-link" href="#" data-id="item_des"><span>活动介绍</span></a>
			</div>
			<div class="atab-box-area none">
				<div class="atab-box-area-dispay" id="item_info">
					<table class="party_table" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td class="key">活动开始：</td>
							<td>{date $detail[begintime]}</td>
						</tr>
						<tr>
							<td class="key">活动结束：</td>
							<td>{date $detail[endtime]}</td>
						</tr>
						<tr>
							<td class="key">活动地址：</td>
							<td>{print:modoer area(aid/$detail[aid])}&nbsp;$detail[address]</td>
						</tr>
						<tr>
							<td class="key">性别限制：</td>
							<td>{print lang('party_sex_'.$detail[sex])}</td>
						</tr>
						<!--{if $applyprice}-->
						<tr>
							<td class="key" align="right">报名费用：</td>
							<td>$applyprice[0] {print:member point(point/$applyprice[1]/keyname/u|n)}</td>
						</tr>
						<!--{/if}-->
						<tr>
							<td class="key">活动费用：</td>
							<td>{$detail[price]} 元人民币/人</td>
						</tr>
						<tr>
							<td class="key">活动人数：</td>
							<td>{$detail[plannum]} 人</td>
						</tr>
						<tr>
							<td class="key">报名截止：</td>
							<td>{date $detail[joinendtime]}</td>
						</tr>
						<tr>
							<td class="key">报名人数：</td>
							<td>
								已有 <span class="font_1"><b>$detail[num]</b></span> 人报名
								<!--{if $joined}-->
									<span class="font_2">我已报名</span>
								<!--{else}-->
									<!--{if $detail[flag] != '1'}-->
										<span class="font_2">[已停止报名]</span>
									<!--{/if}-->
								<!--{/if}-->

							</td>
						</tr>
					</table>
						</div>
				<div class="atab-box-area-dispay" id="item_creator">
					<table class="party_table" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td class="key">发起人：</td>
							<td>
								<!--{if $detail[uid]}-->
								$detail[username]
								<!--{else}-->
								<b class="font_1">本活动由网站发起</b>
								<!--{/if}-->
							</td>
						</tr>
						<tr>
							<td class="key">联系人：</td>
							<td>$detail[linkman]</td>
						</tr>
						<tr>
							<td class="key">联系方式：</td>
							<td>
								<!--{if !$MOD[joined_showcontact] || $joined}-->
								$detail[contact]
								<!--{else}-->
								报名后可见
								<!--{/if}-->
							</td>
						</tr>
					</table>
						</div>
						<div class="atab-box-area-dispay" id="item_des">
					<div class="txt-comm txt-grey" style="padding:10px;">
						$detail[des]
					</div>
						</div>
			</div>
		</div>

		<!--{if $detail[flag] == '1'}-->
		<div class="mt10">
			<!--{if $joined}-->
			<a class="btn btn-default block txt-gray" href="javascript:">我已经报名了</a>
			<!--{else}-->
			<a class="btn btn-mycolor block" href="{url party/mobile/do/detail/id/$detail[partyid]/op/apply}" id="apply-btn">我要报名</a>
			<!--{/if}-->
		</div>
		<!--{/if}-->

		<div class="list-group mt10">
						<a class="list-group-item none" href="{url party/mobile/do/detail/id/$detail[partyid]/op/content}" data-name="content">
							<div class="fr">
								<span class="arrow"></span>
							</div>
							活动作业
						</a>
					<!--{if $pictures>0}-->
							<a class="list-group-item" href="{url party/mobile/do/detail/id/$detail[partyid]/op/pictures}">
								<div class="fr">
									<span class="arrow"></span>
								</div>
								活动图片($pictures)
							</a>
					<!--{/if}-->
						<a class="list-group-item"  href="{url party/mobile/do/detail/id/$detail[partyid]/op/comments}">
							<div class="fr">
								<span class="arrow"></span>
							</div>
							活动咨询($comments)
						</a>
			</div>

	</div>
</div>
<div class="panel-comm panel-default none" id="frm_apply">
	<div class="panel-body">
		<div class="form-box">
				<form action="{url party/mobile/do/detail/id/$partyid/op/apply}" method="post">
						<div class="form-item">
								<label>联系人(必填)：</label>
								<input name="linkman" placeholder="请选择您的姓名" type="text" required>
						</div>
						<div class="form-item">
								<label>性别(必填)：</label>
								<div class="item-inline">
									<label><input type="radio" name="sex" value="1">男</label>
						<label><input type="radio" name="sex" value="2">女</label>
								</div>
						</div>
						<div class="form-item">
								<label>联系方式(必填)：</label>
								<input name="contact" placeholder="请输入您的手机号" type="text" required>
						</div>
						<div class="form-item">
								<label>申请说明(选填)：</label>
								<textarea name="comment"></textarea>
						</div>
						<div class="form-submit">
								<div class="btn-group btn-group-auto">
									<input type="hidden" name="in_ajax" value="1">
									<input type="hidden" name="dosubmit" value="apply">
									<div class="btn-group">
										<button type="button" class="btn btn-mycolor" data-type="submit">提交</button>
									</div>
									<div class="btn-group">
										<button type="button" class="btn btn-default" data-type="close">关闭</button>
									</div>
								</div>
						</div>
				</form>
		</div>
	</div>
</div>
<script>
var mdrawer;
$(function() {

	//Tab
	$('.atab-box').m_nav();

	$('#apply-btn').click(function() {
		check_party_apply();
		return false;
	});
	
	//申请表单对话框
	mdrawer = new $.m_drawer('#frm_apply', {}, {
		//提交对话框表单
		onSubmit:function(obj, applybox) {
			apply_submit();
			return false;
		}
	});

	//检测精彩回顾是否存在
	check_party_content();

});

function check_party_apply() {
	var apply_btn = $('#apply-btn');
	var url = apply_btn.attr('href').url();
	$.post(url, {in_ajax:1}, function(data) {
				if(is_message(data)) {
						myAlert(data);
				} else if(is_json(data)) {
						ret = parse_json(data);
						if(ret.code != 200) {
								alert(ret.message+'('+ret.code+')');
						} else {
								mdrawer.open(function(drawer, applybox) {
										if(ret.data && ret.data.price) {
												applybox.find('.J_apply_price').remove();
												var frmItem = $('<div class="form-item item-inline J_apply_price"></div>')
														.append('<label>报名费用：</label>')
														.append('<span class="font_1">'+ret.data.price+ret.data.pt_name+'</span>')
												applybox.find('div.form-submit').before(frmItem);
										}
								});
						}
				} else {
						alert('未知错误.');
				}
	});
}

function check_party_content() {
	var a = $('a[data-name="content"]');
	var url = a.attr('href').url();
	$.get(url, {check_exist:1, in_ajax:1}, function(data) {
		if(data=='ok') {
			a.show();
		}
	});
}

function apply_submit() {
	var frm = $('#frm_apply form');
	var url = frm.attr('action').url();
	$.post(url, frm.serialize(), function(data) {
		if(is_message(data)) {
			myAlert(data);
			return;
		} else if(is_json(data)) {
			var ret = parse_json(data);
			if(ret.code!=200) {
				alert(ret.message+'('+ret.code+')');
				return;
			} else {
				alert('报名成功！请继续关注本此活动。');
				$('a[data-type="apply-btn"]').removeClass().addClass('disabled');
				mdrawer.close();
				return;
			}
		}
	});
}

</script>
{include mobile_template('footer')}